﻿using log4net;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace WoSoft.PACS.Utility
{
    /// <summary>
    /// 日志帮助类
    /// </summary>
    public class LogHelper
    {
        static LogHelper()
        {

            var config = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            var filePath = "";
            if (Path.GetFileName(config) == "web.config")
            {//web应用程序访问 
                filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Bin/Configs/log4net.config");
            }
            else
            {//windesktop程序 
                filePath = AppDomain.CurrentDomain.BaseDirectory + "\\Configs\\log4net.config";
            }

            FileInfo logConfig = new FileInfo(filePath);
            log4net.Config.XmlConfigurator.Configure(logConfig);
        }

        private static ILog log = LogManager.GetLogger("log-data");

        /// <summary>
        /// 写入错误日志
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public static void Error(string message)
        {
            log.Error(message);
        }

        /// <summary>
        /// 写入错误日志
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public static void Error(string message, Exception ex)
        {
            log.Error(message, ex);
        }

        /// <summary>
        /// 写入消息 
        /// </summary>
        /// <param name="message"></param>
        public static void Info(string message)
        {
            log.Info(message);
        }

        /// <summary>
        /// 写入消息 
        /// </summary>
        /// <param name="message"></param>
        public static void Info(string message, Exception ex)
        {
            log.Info(message, ex);
        }

        /// <summary>
        /// 写入警告信息
        /// </summary>
        /// <param name="message"></param>
        public static void Warn(string message)
        {
            log.Warn(message);
        }

        /// <summary>
        /// 写入警告信息
        /// </summary>
        /// <param name="message"></param>
        public static void Warn(string message, Exception ex)
        {
            log.Warn(message, ex);
        }

        public static void Debug(string message)
        {
            log.Debug(message);
        }

    }
}
